<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>EOC监控系统</title>
<!--#include file="lib/plugins.asp"-->
<link rel="stylesheet" href="lib/jquery.timepicker/jquery-ui-timepicker-addon.css" type="text/css">
<script type="text/javascript" src="lib/jquery.timepicker/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="lib/jquery.timepicker/localization/jquery-ui-timepicker-zh-CN.js"></script>
<style type="text/css">
  .ui-datepicker table {
    border: 0;
  }
</style>
<script type="text/javascript">
  $(function() {
    $(".datetimepicker").datetimepicker({
        minDate:0,
        maxDate:'1w',
        showSecond: true,
        timeFormat: 'hh:mm:ss'

    });
    function verifyIP(ip){
        re=/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
        return re.test(ip);
    }
    $("#form1").submit(function(){
        //e.preventDefault();
        //var   s   =   "2005-12-15   09:41:30";   
        //var   d   =   new   Date(Date.parse(s.replace(/-/g,   "/")));
        var dtStart=new Date(Date.parse($("#dtStart").val().replace(/-/g, "/")));
        var dtEnd=new Date(Date.parse($("#dtEnd").val().replace(/-/g, "/")));
        if($("#dtStart").val()!=""&&$("#dtEnd").val()!=""){
            //alert(dtStart.toLocaleString());
            //alert(dtEnd.toLocaleString());
            ndip=$("#ndip").val();
            if(verifyIP(ndip)){
                if(dtEnd<=dtStart){
                    //alert("here");
                    //$("#form1").submit();
                    alert("结束时间早于开始时间错误");
                    return false;
                }
            }else{
                alert("IP地址错误");
                return false;
            }
        }else{
            alert("时间错误");
            return false;
        }
    });
  });
</script>
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
Set conn_ndflow = Server.CreateObject("ADODB.CONNECTION")
db_ndflow = "DRIVER=SQLite3 ODBC Driver;Database="&Server.MapPath("ndflow.db3")
conn_ndflow.Open db_ndflow

' if not CheckPostFlag(session("aaPostFlag"),1,3) then call JumpErrorPage(2)

id=saferequest("id",1)
submit=saferequest("submit",0)
if id="" then
  action="add"
  dtDate=date()
else
  action="edit"
end if
if submit<>"" then
  '事务开始
  conn_ndflow.BeginTrans
  ' on error resume next
  action=request("action")
  ndip=request("ndip")
  iport=request("iport")
  dtStart=request("dtStart")
  dtEnd=request("dtEnd")
  dtStart=FormatTime(dtStart,"{Y}-{m}-{d} {h}:{n}:{s}")
  dtEnd=FormatTime(dtEnd,"{Y}-{m}-{d} {h}:{n}:{s}")
  ' dtDate=replace(dtDate,"/","-")&" 00:00:00"
  if action="edit" then
    '如果是编辑状态，提交或保存按钮把所有信息更新
    if submit="保存" then
      sql_act="update ndflow set ndip='"&ndip&"',iport="&iport&",dtStart='"&dtStart&"',dtEnd='"&dtEnd&"' where id="&id
      ' response.write(sql_act)
      ' response.end
    end if
    if submit="删除" then
      sql_act="delete from ndflow where id="&id
    end if
    call ExecuteCommand_ndflow(sql_act,false,conn_ndflow)
  end if
  
  if action="add" then
    '如果是添加状态，新增和提交按钮起同样作用
    sql_act="insert into ndflow(ndip,iport,dtStart,dtEnd) values('"&ndip&"',"&iport&",'"&dtStart&"','"&dtEnd&"')"
    ' response.write(sql_act)
    ' response.end
    id=ExecuteCommand_ndflow(sql_act,true,conn_ndflow)
  
    ' call AddFee()
    
  end if
  
  '事务提交
  ' if conn.Errors.Count=0 then 
    ' conn.CommitTrans  '如果没有conn错误，则执行事务提交
  ' else
    ' conn.RollbackTrans '否则回滚
  ' end if

  if err.number=0 then 
    conn_ndflow.CommitTrans  '如果没有conn错误，则执行事务提交
  else
    conn_ndflow.RollbackTrans '否则回滚
    '回滚后的其他操作
    'strerr=err.Description
    url=request.ServerVariables("http_host")&request.ServerVariables("url")
    Response.Write "数据库错误！<br /><font color=red>Error # " & CStr(Err.Number) & "<br />" & Err.Description & "<br />Source: " & Err.Source &"<br />错误页面："&url&"</font><br />"
    Response.End
  end if
end if

if submit="删除" then response.redirect("ndflow.asp")
if id<>"" then
  sql = "select * from ndflow where id="&id
  Set rs = Server.CreateObject("ADODB.Recordset")
  rs.Open sql,conn_ndflow,1,1
  if not rs.eof then
    ndip=rs("ndip")
    dtStart=rs("dtStart")
    dtEnd=rs("dtEnd")
    iport=CLng(rs("iport"))
  else
    'response.write("未找到数据")
    response.redirect("error.asp?id=1")
  end if
  rs.close
  set rs=nothing
end if
%>
<body>
<!--#include file="lib/header.asp"-->
<!--#include file="lib/nav.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
<!--#include file="lib/col2.asp"-->
  <div id="col3" role="main">
    <div id="col3_content" class="clearfix">
      <form id="form1" name="form1" method="post" class="yform columnar" role="application">
                NDIP
                <input name="ndip" id="ndip" type="text" size="15" maxlength="15" value="<%=ndip%>" />
                
                <select name="iport" id="iport">
                    <option value="2" <%if iport=2 then response.write("selected='selected'")%>>以太口</option>
                    <option value="1" <%if iport=1 then response.write("selected='selected'")%>>同轴口</option>
                </select>
                开始时间
                <input class="datetimepicker" name="dtStart" id="dtStart" type="text" readonly="readonly" size="19" value="<%if isdate(dtstart) then response.write(FormatTime(dtstart,"{Y}-{m}-{d} {h}:{n}:{s}"))%>" />
                结束时间
                <input class="datetimepicker" name="dtEnd" id="dtEnd" type="text" readonly="readonly" size="19" value="<%if isdate(dtend) then response.write(FormatTime(dtend,"{Y}-{m}-{d} {h}:{n}:{s}"))%>" />
          <input id="id" type="hidden" value="<%=id%>" />
          <input id="action" name="action" type="hidden" value="<%=action%>" />
      <% if CheckLogin() then %>
        <%if action="add" then%>
          <input type="submit" id="submit_add" name="submit" value="新增" />
        <%end if%>
        <%if action="edit" then%>
          <input type="submit" id="submit_sav" name="submit" value="保存" />
        <%end if%>
        <%if action="edit" then%>
          <input type="submit" id="submit_del" name="submit" value="删除" />
        <%end if%>
      <% end if %>
      </form>
        <table id="tablelist" class="full">
            <thead>
                <tr><th colspan="8" scope="col">监控列表</th></tr>
            </thead>
            <tbody>
                <tr>
                    <th scope="col">ID</th>
                    <th scope="col">NDIP</th>
                    <th scope="col">监控端口</th>
                    <th scope="col">开始时间</th>
                    <th scope="col">结束时间</th>
                    <th scope="col">监控状态</th>
                    <th scope="col">查看记录</th>
                    <th scope="col">流量曲线</th>
                </tr>
                <%
                    sql = "select * from ndflow order by id desc"
                    Set rs = Server.CreateObject("ADODB.Recordset")
                    rs.Open sql,conn_ndflow,1,1
                    do while not rs.eof
                %>
                <tr>
                    <th class="sub" scope="row"><a href="ndflow.asp?id=<%=rs("id")%>"><%=rs("id")%></a></th>
                    <td><%=rs("ndip")%></td>
                    <td>
                    <%
                        select case rs("iport")
                            case 1:response.write("同轴口")
                            case 2:response.write("以太口")
                        end select
                    %>
                    </td>
                    <td><%=FormatTime(rs("dtStart"),"{Y}-{m}-{d} {h}:{n}:{s}")%></td>
                    <td><%=FormatTime(rs("dtEnd"),"{Y}-{m}-{d} {h}:{n}:{s}")%></td>
                    <td>
                    <%
                        thistime=now
                        
                        if thistime<rs("dtStart") then response.write("未开始")
                        if thistime>rs("dtEnd") then response.write("已结束")
                        if thistime>rs("dtStart") and thistime<rs("dtEnd") then response.write("监控中")
                    
                    %>
                    </td>
                    <td><a href="ndflowlog.asp?ndflowid=<%=rs("id")%>" target="_blank">记录</a></td>
                    <td><a href="ndflowchart.asp?ndflowid=<%=rs("id")%>" target="_blank">曲线</a></td>
                </tr>
                <%
                    
                        rs.movenext
                    loop
                    rs.close
                    set rs=nothing
                
                %>
                
            </tbody>
        </table>
    </div>
  </div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<%
conn_ndflow.close
set conn_ndflow=nothing

%>
<!--#include file="lib/connclose.asp"-->

